home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / lang / FPL_v147.lha / fpl / src / debugmem.h < prev    next >
C/C++ Source or Header  |  1996-08-02  |  4KB  |  130 lines

  1. /******************************************************************************
  2.  *                        FRONTEC RAILWAY SYSTEMS AB
  3.  * ----------------------------------------------------------------------------
  4.  *
  5.  * Project: FR-3000 CS
  6.  * $Source: /home/pop/proj/rail/usr/dast/dancer/dancer/RCS/debugmem.h,v $
  7.  * $Revision: 1.2 $
  8.  * $Date: 1996/02/29 14:11:17 $
  9.  * $Author: dast $
  10.  * $State: Exp $
  11.  * $Locker:  $
  12.  *
  13.  * ----------------------------------------------------------------------------
  14.  * $Log: debugmem.h,v $
  15.  * Revision 1.2  1996/02/29 14:11:17  dast
  16.  * fixed some action defines
  17.  *
  18.  * Revision 1.1  1996/01/18 12:32:11  dast
  19.  * Initial revision
  20.  *
  21.  * Revision 3.6  1994/11/30  08:59:00  dast
  22.  * Fixed the header to work
  23.  *
  24.  *****************************************************************************/
  25.  
  26. #ifndef DEBUGMEM_H
  27. #define DEBUGMEM_H
  28.  
  29. #define _FREE (free) /* function to use when freeing memory for real */
  30. #define _MALLOC (AllocMem) /* function to use when allocing memory for real */
  31.  
  32. #define FREE_WITH_SIZE (FreeMem)
  33. /* define if such a function is in use!
  34.    Overrides the 'FREE' define */
  35.  
  36. /* #define LOG printf /* printf style function to call */
  37.                                   
  38.                                   
  39. /* Prototype the memory functions: */
  40. #ifdef FREE_WITH_SIZE
  41. void     DBG_free        ( void *, int, char *, int );
  42. #else
  43. void     DBG_free        ( void *, char *, int );
  44. #endif
  45. void *    DBG_malloc        ( int, char *, int );
  46. void *    DBG_realloc        ( void *, int, char *, int );
  47. void *    DBG_calloc        ( int, int, char *, int );
  48. void     DBG_MemList        ( );
  49. int     DBG_UsedMem        ( );
  50. long     DBG__CheckMem    ( void *, char *, int );
  51. char *  DBG_Strdup      (char *, char *, int);
  52. int     DBG_NewFunc     ( );
  53. void    DBG_Verbose     ( char );
  54.  
  55. /* This function checks a memory block allocated using
  56.    the DBG_malloc() for overwritten cookies.
  57.    Returns TRUE if any error was found.
  58.    NOTE: any failure in this check will invoke the same
  59.    actions as if a regular DBG_free() failed. */
  60. #define DBG_CheckMem(mem) DBG__CheckMem(mem, __FILE__, __LINE__)
  61.  
  62. /* replace malloc() with the new routine */
  63. #define malloc(x) DBG_malloc(x, __FILE__, __LINE__)
  64.  
  65. /* replace calloc() with the new routine */
  66. #define calloc(x, y) DBG_calloc(x, y, __FILE__, __LINE__)
  67.  
  68. /* replace realloc() with the new routine */
  69. #define realloc(p, x) DBG_realloc(p, x, __FILE__, __LINE__)
  70.  
  71. /* replace free() with the new routine */
  72. #define free(x) DBG_free(x, __FILE__, __LINE__)
  73.  
  74. #ifdef FREE_WITH_SIZE
  75. /* replace FreeMem() with the new routine */
  76. #define FreeMem(x, y) DBG_free(x, y, __FILE__, __LINE__)
  77. #define AllocMem(x, y) DBG_malloc(x, __FILE__, __LINE__)
  78. #endif
  79.  
  80. /* replace strdup() with the new routine */
  81. #define strdup(x) DBG_Strdup(x, __FILE__, __LINE__)
  82.  
  83. /* store source code information on malloc */
  84. #define SOURCE_INFO
  85.  
  86. /* number of bytes to allocate before every block */
  87. #define PRE_COOKIE_SIZE 8
  88.  
  89. /* number of bytes to allocate after every block */
  90. #define POST_COOKIE_SIZE 8
  91.  
  92. /* byte to fill pre cookie with */
  93. #define PRE_COOKIE_FILL_BYTE 0xbb
  94.  
  95. /* byte to fill post cookie with */
  96. #define POST_COOKIE_FILL_BYTE 0xdd
  97.  
  98. /* Actions to perform when any error has been discovered in the
  99.    cookies. The parameters to these macros are:
  100.    
  101.    Number_I   - Number of overwritten bytes
  102.    FSource_PC - Source file of the free()
  103.    FLine_I    - Line number of the free()
  104.    MSource_PC - Source file of the malloc()
  105.    MLine_I    - Line number of the malloc()
  106.    */
  107.  
  108. extern char MT_LogString_AC[];
  109.  
  110. #ifdef LOG
  111. #define PRE_COOKIE_ACTION(Number_I, FSource_PC, FLine_I, MSource_PC, MLine_I) \
  112.     LOG("PRE COOKIE %d bytes (free: %s/%d malloc: %s/%d)!",\
  113.            Number_I, FSource_PC, FLine_I, MSource_PC, MLine_I);
  114.  
  115. #define POST_COOKIE_ACTION(Number_I, FSource_PC, FLine_I, MSource_PC, MLine_I)\
  116.     LOG("POST COOKIE %d bytes (free: %s/%d malloc: %s/%d)!",\
  117.            Number_I, FSource_PC, FLine_I, MSource_PC, MLine_I);
  118.  
  119. #define MALLOCED(size,source,lyne)\
  120.     LOG(">>> allocated %d bytes in %s line %d\n", size, source, lyne);
  121.  
  122. #define FREED(size,source,lyne)\
  123.     LOG("<<< freed %d bytes in %s line %d\n", size, source, lyne);
  124.  
  125. #define CHECKMEMED(size,source,lyne)\
  126.     LOG("### checked %d bytes in %s line %d\n", size, source, lyne);
  127. #endif /* LOG */
  128.  
  129. #endif
  130.